﻿#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>
#include "jmutex.h"
#include "jthread.h"

// class ThreadTask

class ThreadTask : public JThread
{
public:
    explicit ThreadTask();
    ~ThreadTask();

    void startThread();
    void stopThread();

    // JRunnable interface
public:
    void run();

private:
    bool q_running;
    JMutex q_mutex;
};

// class ThreadDialog

class QPushButton;

class ThreadDialog : public QDialog, public JThreadObserver
{
    Q_OBJECT
public:
    explicit ThreadDialog(QWidget *parent = 0);
    ~ThreadDialog();

    // JThreadObserver interface
public:
    void started();
    void finished();
    void terminated();
    void suspended();
    void resumed();

public Q_SLOTS:
    void onButtonStart();
    void onButtonStop();

private:
    ThreadTask *q_threadTask;
    QPushButton *q_buttonStart;
    QPushButton *q_buttonStop;
};

#endif // DIALOG_H
